"""
API 处理后返回的数据类型
"""

import uuid
from collections import namedtuple
from common.retcode import TransferType, TransferStatus

__all__ = ['FileInfo', 'RecInfo', 'PathInfo', 'UpCode', 'MkCode', 'UpInfo',
		   'ShareCode', 'FolderTree', 'ShareInfo', 'UserInfo', 'TransferInfo', 'SettingInfo']


_base_info = ['name', 'id', 'pid', 'ctime', 'optime', 'size', 'ftype', 'isFolder', 'durl']
_file_info = (*_base_info, 'isStarred', 'account', 'count')
_rec_info = [*_base_info, 'isFamily', 'path', 'fid']
_share_info = ['pwd', 'copyC', 'downC', 'prevC', 'url', 'path',
			   'need_pwd', 's_type', 's_mode', 'r_stat', *_base_info]

# 主文件
FileInfo = namedtuple('FileInfo', _file_info, defaults=('',) * len(_file_info))
# 回收站文件
RecInfo = namedtuple('RecInfo', _rec_info, defaults=('',) * len(_rec_info))
# 文件路径
PathInfo = namedtuple('PathInfo', ['name', 'id', 'isCoShare'])

UpCode = namedtuple('UpCode', ['code', 'id', 'quick_up', 'path'], defaults=(0, '', False, ''))
MkCode = namedtuple('MkCode', ['code', 'id'], defaults=(0, ''))
ShareCode = namedtuple('ShareCode', ['code', 'url', 'pwd', 'et'], defaults=(0, '', '', ''))

FolderTree = namedtuple('FolderTree', ['name', 'id', 'pid', 'isParent'], defaults=('',) * 4)

ShareInfo = namedtuple('ShareInfo', _share_info, defaults=('',) * len(_share_info))
UserInfo = namedtuple('UserInfo', ['id', 'account', 'nickname', 'used', 'quota', 'vip', 'endTime',
								   'beginTime', 'domain'], defaults=('',) * 9)

class UpInfo(object):
	def __init__(self):
		self.name = ''
		self.path = ''
		self.fid = -11
		self.totalSize = 0
		self.nowSize = 0
		self.status = TransferStatus.WAITING
		self.exist = False

class TransferInfo(object):
	def __init__(self):
		self.gid = str(uuid.uuid1())
		self.name = ''
		self.path = ''
		self.type = TransferType.DOWNLOAD
		self.fid = -11
		self.ftype = ''
		self.isFolder = False
		self.status = TransferStatus.WAITING
		self.totalSize = 0
		self.nowSize = 0
		self.lastTick = 0
		self.speed = 0

		self.force = False # 强制上传已经存在的文件(文件名、大小一致的文件)
		self.mkdir = True # 是否在 parrent_fid 创建父文件夹
		self.check = True # 是否进行md5校验
		self.index = 0 # 当前传输中的文件序号
		self.upload_info_list = []

		self._upload_type = 0
		self._upload_files = []

class SettingInfo(object):
	def __init__(self):
		self.downDir = ''
